#include<iostream>
using namespace std;
bool judge(int n)
{
	if (n % 400 == 0 || (n % 4 == 0 && n % 100 != 0)) {
		return 1;
	}
	return 0;
}
int main()
{
	int y, m;
	cin >> y >> m;
	if (judge(y)) {
		int month[13] = { 0,31,29,31,30,31,30,31,31,30,31,30,31 };
		cout << month[m] << endl;
	}
	else {
		int month[13] = { 0,31,28,31,30,31,30,31,31,30,31,30,31 };
		cout << month[m] << endl;
	}
	return 0;
}